.TH std::basic_string_view::swap 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_string_view::swap \- std::basic_string_view::swap

.SH Synopsis
   constexpr void swap( basic_string_view& v ) noexcept;  \fI(since C++17)\fP

   Exchanges the view with that of v.

.SH Parameters

   v - view to swap with

.SH Return value

   \fI(none)\fP

.SH Complexity

   Constant.

.SH Example


// Run this code

 #include <iostream>
 #include <string_view>

 int main()
 {
     std::string_view a = "AAA";
     std::string_view b = "BBBB";

     std::cout << "Before swap:\\n"
                  "a = " << a << "\\n"
                  "b = " << b << "\\n\\n";

     a.swap(b);

     std::cout << "After swap:\\n"
                  "a = " << a << "\\n"
                  "b = " << b << '\\n';
 }

.SH Output:

 Before swap:
 a = AAA
 b = BBBB

 After swap:
 a = BBBB
 b = AAA

.SH See also

   swap        swaps the values of two objects
               \fI(function template)\fP
   swap_ranges swaps two ranges of elements
               \fI(function template)\fP
               swaps the contents
   swap        \fI(public member function of std::basic_string<CharT,Traits,Allocator>)\fP

